home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Chans / x40084 / ut_rts.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  8.5 KB  |  400 lines

  1. /* ut_rts.c - X400 rts utilities */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Chans/x40084/RCS/ut_rts.c,v 6.0 1991/12/18 20:13:50 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Chans/x40084/RCS/ut_rts.c,v 6.0 1991/12/18 20:13:50 jpo Rel $
  9.  *
  10.  * $Log: ut_rts.c,v $
  11.  * Revision 6.0  1991/12/18  20:13:50  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include <isode/rtsap.h>
  19. #include "util.h"
  20. #include "rtsparams.h"
  21. #include "chan.h"
  22. #include "Rts84-types.h"
  23.  
  24. static char        *build_inkey();
  25. static char        *pretty_key = NULLCP;       /* -- for logging only -- */
  26. static void        print_remote_info();
  27.  
  28. char            *remote_site = NULLCP;
  29. char            *undefined_bodyparts = NULLCP;
  30.  
  31. static int remote_info_not_found();
  32.  
  33.  
  34.  
  35. /* ---------------------  Begin     Routines  -------------------------------- */
  36.  
  37.  
  38.  
  39.  
  40. int rts_encode_request (ppe, request, mta, pass)
  41. PE                *ppe;
  42. struct type_Rts84_Request    **request;
  43. char                *mta, *pass;
  44. {
  45.     struct type_Rts84_Request    *req;
  46.     struct member_Rts84_0        *rq;
  47.  
  48.     PP_TRACE (("rts_encode_request (%s %s)", mta, pass));
  49.  
  50.     req = (struct type_Rts84_Request *) calloc (1, sizeof (*req));
  51.     if (req == NULL) {
  52.         do_reason ("rts_encode_request/Unable to calloc");
  53.         return NOTOK;
  54.     } 
  55.  
  56.     rq = req->un.choice_Rts84_1 =
  57.         (struct member_Rts84_0 *) calloc (1, sizeof (*rq));
  58.     if (rq == NULL) {
  59.         do_reason ("rts_encode_request/Unable to calloc");
  60.         return NOTOK;
  61.     } 
  62.  
  63.     if (mta == NULLCP)
  64.         req -> offset = type_Rts84_Request_1;
  65.     else {
  66.         req->offset = type_Rts84_Request_2;
  67.         rq->mTAName = str2qb (mta, strlen (mta), 1);
  68.         rq->password = ia5s2prim (pass, strlen (pass));
  69.     }
  70.  
  71.     *request = req;
  72.  
  73.     if (encode_Rts84_Request (ppe, 1, 0, NULLCP, req) == NOTOK) {
  74.         do_reason ("rts_encode_request/Rejected: '%s'", PY_pepy);
  75.         return NOTOK;
  76.     }
  77.  
  78.     PP_TRACE (("x400out84/encode_Rts84_Request successful!"));
  79.     return OK;
  80. }
  81.  
  82.  
  83.  
  84.  
  85. int parameter_checks (pe, mta, pass, key, checks)
  86. PE    pe;
  87. char    *mta; 
  88. char    *pass;
  89. char    *key;
  90. int    checks;
  91. {
  92.     struct type_Rts84_Request    *req = NULL;
  93.     struct member_Rts84_0        *rq;
  94.     char                *remotesite = NULLCP;
  95.     char                *password = NULLCP;
  96.     int                retval = NOTOK;
  97.  
  98.     PP_TRACE (("parameter_checks('%s', '%s', '%s', '%s')",
  99.         key ? key : "null", 
  100.         mta ? mta : "null",
  101.         pass ? pass : "null", 
  102.         checks ? "true" : "false"));
  103.  
  104.     if (decode_Rts84_Request (pe, 0, NULLIP, NULLVP, &req) == NOTOK) {
  105.         do_reason ("parameter_checks/Rejected: '%s'", PY_pepy);
  106.         goto parameter_checks_free;
  107.     }
  108.  
  109.     print_remote_info (key, req);
  110.  
  111.     if (checks == FALSE) {
  112.         retval = OK;
  113.         goto parameter_checks_free;
  114.     }
  115.  
  116.     if (req->offset == type_Rts84_Request_1) {
  117.         PP_NOTICE (("x400out84/parameter_checks() are not required"));
  118.         retval = OK;
  119.         goto parameter_checks_free;
  120.     }
  121.  
  122.     rq = req->un.choice_Rts84_1;
  123.  
  124.     remotesite = qb2str (rq->mTAName);
  125.  
  126.     if (rq->password->pe_form != PE_FORM_PRIM) {
  127.         do_reason ("parameter_checks/Password has a bad format");
  128.         goto parameter_checks_free;
  129.     }
  130.     else {
  131.         int len;
  132.         password = prim2str (rq->password, &len);
  133.     }
  134.  
  135.     PP_TRACE (("parameter_checks MTA=%s, P=%s", remotesite, password));
  136.  
  137.     if (mta && lexequ (remotesite, mta) != 0) {
  138.         do_reason ("parameter_checks/MTAName mismatch: specified='%s' received='%s'", mta, remotesite);
  139.         goto parameter_checks_free;
  140.     }
  141.  
  142.  
  143.     if (lexequ (pass, "dflt") == 0) {
  144.         retval = OK;
  145.         goto parameter_checks_free;
  146.     }
  147.  
  148.  
  149.     if (pass && lexequ ((char *)password, pass) != 0) {
  150.         do_reason ("parameter_checks/Password mismatch: specified='%s' received='%s'", pass, (char *)password);
  151.         goto parameter_checks_free;
  152.     }
  153.  
  154.     retval = OK;
  155.  
  156. parameter_checks_free: ;
  157.     if (req)        free_Rts84_Request (req);
  158.     if (remotesite)        free (remotesite);
  159.     if (password)        free ((char *)password);
  160.  
  161.     return retval;
  162. }
  163.  
  164.  
  165.  
  166.  
  167. /* -- Checks P1 User-data: mTAName and password -- */
  168.  
  169. rts_decode_request (rts, ppe, prq, chan)
  170. struct RtSAPstart        *rts;
  171. PE                *ppe;
  172. struct type_Rts84_Request    **prq;
  173. CHAN                *chan;
  174. {
  175.     char        *key;
  176.     RtsParams    *rp;
  177.     int        checkit = TRUE;
  178.  
  179.     key = build_inkey (rts);
  180.  
  181.     PP_TRACE (("x400in84/rts_decode_request (%s)", key));
  182.  
  183.  
  184.     if ((rp = tb_rtsparams (chan->ch_in_table, key)) == NULL) 
  185.         return (remote_info_not_found (rts, ppe, prq, key, chan));
  186.  
  187.  
  188.     /* -- Check that the right info is in the tables -- */
  189.     if (rp->their_internal_ppname == NULLCP) {
  190.         PP_LOG (LLOG_EXCEPTIONS, 
  191.             ("No rname specified in the entry '%s'", key));
  192.         return RTS_VALIDATE;
  193.     }
  194.  
  195.     if (rp->their_name == NULLCP) {
  196.         PP_LOG (LLOG_EXCEPTIONS, 
  197.             ("No rmta specified in the entry '%s'", key));
  198.         return RTS_VALIDATE;
  199.     }
  200.  
  201.     if (lexequ (chan -> ch_in_info, "sloppy") == 0 
  202.         || lexequ (rp -> info_mode, "sloppy") == 0)
  203.             checkit = FALSE; 
  204.  
  205.     if (parameter_checks (rts -> rts_data, rp -> their_name,
  206.                   rp -> their_passwd, key, checkit) == NOTOK) {
  207.         PP_LOG (LLOG_EXCEPTIONS, ("Parameter check failed"));
  208.         return RTS_VALIDATE;
  209.     }
  210.  
  211.  
  212.     /* -- encode new Connect Accept Data -- */
  213.     rts_encode_request (ppe, prq, rp -> our_name, rp -> our_passwd);
  214.  
  215.  
  216.     /* -- set the remote site value -- */
  217.     if (remote_site)
  218.         free (remote_site);
  219.     if (rp -> their_internal_ppname == NULLCP) {
  220.         PP_LOG (LLOG_EXCEPTIONS, ("No internal name for %s", key));
  221.         remote_site = strdup (key);
  222.     }
  223.     else remote_site = strdup (rp -> their_internal_ppname);
  224.  
  225.  
  226.     /* --- *** --- 
  227.     if "undefined" set in eit - replace with rp->info_undefined
  228.     --- *** --- */
  229.  
  230.     if (undefined_bodyparts) {
  231.         free (undefined_bodyparts);
  232.         undefined_bodyparts = NULLCP;
  233.     }
  234.     if (rp -> info_undefined)
  235.         undefined_bodyparts = strdup (rp -> info_undefined);
  236.  
  237.     RPfree (rp);
  238.     return OK;
  239. }
  240.  
  241.  
  242.  
  243. /* ---------------------  Static  Routines  ------------------------------- */
  244.  
  245.  
  246.  
  247.  
  248.  
  249. static int  remote_info_not_found (rts, ppe, prq, key, chan)
  250. struct RtSAPstart        *rts;
  251. PE                *ppe;
  252. struct type_Rts84_Request    **prq;
  253. char                *key;
  254. CHAN                *chan;
  255. {
  256.     RtsParams        *rp;  /* --- contains default values --- */
  257.  
  258.  
  259.     PP_TRACE (("remote_info_not_found()"));
  260.  
  261.     parameter_checks (rts -> rts_data, NULLCP, NULLCP, key, FALSE);
  262.  
  263.     if (lexequ (chan -> ch_in_info, "sloppy") != 0) {
  264.         PP_LOG (LLOG_EXCEPTIONS, 
  265.             ("No information found in the X.400 incoming tables"));
  266.         return RTS_VALIDATE;
  267.     }
  268.  
  269.     if ((rp = tb_rtsparams (chan -> ch_in_table, "default")) == NULL) {
  270.         PP_LOG (LLOG_EXCEPTIONS, 
  271.             ("No 'default' found in the X.400 incoming tables"));
  272.         return RTS_VALIDATE;
  273.     }
  274.  
  275.  
  276.     /* -- encode new Connect Accept Data -- */
  277.     rts_encode_request (ppe, prq, rp -> our_name, rp -> our_passwd);
  278.     RPfree (rp);
  279.  
  280.     if (remote_site)  free (remote_site);
  281.     remote_site = strdup (key);
  282.  
  283.     PP_LOG (LLOG_EXCEPTIONS, 
  284.         ("No information found in the X.400 incoming tables - BUT have accepted the connection"));
  285.  
  286.     return OK;
  287. }
  288.  
  289.  
  290.  
  291.  
  292. static void print_remote_info (key, req)
  293. char                *key;
  294. struct type_Rts84_Request    *req;
  295. {
  296.     static char        databuf[BUFSIZ];
  297.     char            buf[BUFSIZ];    
  298.     PE            pe;
  299.     char            *cp;
  300.  
  301.  
  302.     bzero (databuf, BUFSIZ);
  303.  
  304.     (void) sprintf (databuf, "key='%s'  ", key);
  305.  
  306.     if (pretty_key) {
  307.         (void) sprintf (buf, "key-pretty='%s'  ", pretty_key);
  308.         (void) strcat (databuf, buf);
  309.     }
  310.  
  311.     if (req->offset == type_Rts84_Request_1) {
  312.         (void) strcat (databuf, "(no more connection data info)");
  313.         goto print_remote_info_end;
  314.     }
  315.  
  316.  
  317.     if ((cp = qb2str (req->un.choice_Rts84_1->mTAName)) != NULLCP) {
  318.         (void) sprintf (buf, "mta='%s'  ", cp);
  319.         (void) strcat (databuf, buf);
  320.         free (cp);
  321.     }
  322.  
  323.     pe = req->un.choice_Rts84_1->password;
  324.  
  325.     if (pe->pe_form == PE_FORM_PRIM)
  326.         if (pe -> pe_prim != 0) {
  327.             int len;
  328.             cp = prim2str (pe, &len);
  329.             (void) sprintf (buf, "password='%s'  ", cp);
  330.             (void) strcat (databuf, buf);
  331.             free (cp);
  332.         }
  333.  
  334.  
  335. print_remote_info_end:    ;
  336.     PP_NOTICE (("Connection from %s", databuf));
  337.     return;
  338. }
  339.  
  340.  
  341.  
  342.  
  343. static char *build_inkey (rts)
  344. struct RtSAPstart        *rts;
  345. {
  346.     struct PSAPaddr        pas;
  347.     struct NSAPaddr        *na;
  348.     int    nna;
  349.     char    *cp;
  350.  
  351.     PP_TRACE (("build_inkey()"));
  352.  
  353.     bzero ((char *)&pas, sizeof pas);
  354.     pas.pa_addr = rts -> rts_initiator.rta_addr;
  355.     for (na = pas.pa_addr.sa_addr.ta_addrs,
  356.         nna = pas.pa_addr.sa_addr.ta_naddr;
  357.         nna > 0; nna --, na ++) {
  358.         if (na -> na_type == NA_TCP) {
  359.             PP_TRACE (("Address is TCP, port set to 0 from %d",
  360.                 na -> na_port));
  361.             na -> na_port = 0;
  362.             /* bug in isode 6.6 */
  363.             if ((cp = index(na -> na_domain, '+')) != NULL)
  364.                 *cp = '\0';
  365.         }
  366.     }
  367.  
  368.     if (pretty_key)        free (pretty_key);    
  369.     pretty_key = strdup(paddr2str (&pas, NULLPA));
  370.  
  371.     return _paddr2str (&pas, NULLPA, -1);
  372. }
  373.  
  374. dump_pdu (qb, str)
  375. struct qbuf *qb;
  376. char *str;
  377. {
  378.     struct qbuf *q;
  379.     char    buf[512];
  380.     char    *cp;
  381.     int    len, n;
  382.  
  383.     PP_LOG (LLOG_PDUS, ("PDU dump: %s", str));
  384.     if ((pp_log_norm -> ll_events & LLOG_PDUS) == 0)
  385.         return;
  386.  
  387.     for (q = qb -> qb_forw; q != qb; q = q -> qb_forw) {
  388.         for (cp = q -> qb_data, len = q -> qb_len; 
  389.              len > 0;) {
  390.             n = min (sizeof (buf) / 2 - 1, len);
  391.             buf[explode (buf, (u_char *)cp, n)] = 0;
  392.             ll_printf (pp_log_norm, "%s", buf);
  393.  
  394.             len -= n;
  395.             cp += n;
  396.         }
  397.     }
  398.     ll_printf (pp_log_norm, "\n-----------\n");
  399. }
  400.